package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.mapper.NewsCommentMapper;
import cn.wolfcode.trip.base.query.CommentQueryObject;
import cn.wolfcode.trip.base.service.INewsCommentService;
import cn.wolfcode.trip.base.util.UserContext;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class INewsCommentServiceImpl implements INewsCommentService {
    @Autowired
    private NewsCommentMapper newsCommentMapper;

    @Override
    public PageInfo query(CommentQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<NewsComment> list = newsCommentMapper.queryForList(qo);
        return new PageInfo(list);
    }

    @Override
    public void saveOrUpdate(NewsComment newsComment) {
        if (newsComment.getId() != null) {
            newsCommentMapper.updateByPrimaryKey(newsComment);
        } else {
            //设置当前用户
            newsComment.setUser(UserContext.getCurrentUser());
            newsCommentMapper.insert(newsComment);
        }

    }

    @Override
    public List<NewsComment> listAll() {
        return null;
    }

    @Override
    public NewsComment get(Long id) {
        return null;
    }

    @Override
    public void saveOrUpdate(NewsComment newsComment, String[] tags) {

    }

    @Override
    public Integer queryCountByNewsCommentId(Long strategyNewsCommentId) {
        return newsCommentMapper.queryCountByNewsCommentId(strategyNewsCommentId);
    }
}
